//
//  HJHTabBarController.swift
//  微博项目
//
//  Created by 黄健桦 on 2016/9/22.
//  Copyright © 2016年 黄健桦. All rights reserved.
//

import UIKit

class HJHTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let hjhTabBar = HJHMainTabBar()
        
        hjhTabBar.composeClosure = { [weak self] in
            print("按钮被点击",self)
            print("----------------")
        }
        
        self.setValue(hjhTabBar, forKey: "tabBar")

        addChildViewControllers()
        
    }

    func addChildViewControllers() {
        addChildViewController(vc: HJHTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(vc: HJHMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(vc: HJHDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(vc: HJHProfileViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    func addChildViewController(vc: UIViewController,title: String,imageName: String) {
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //选中的图片
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)

        //文字颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected)
        
        //设置偏移
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -2)
        
        //修改徽标颜色
        vc.tabBarItem.badgeValue = nil;
        
        let nav = HJHBaseNaviController(rootViewController: vc)
        
        addChildViewController(nav)
        
    }
    

}
